package com.ruoyi.system.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ExtHelper;
import com.ruoyi.common.utils.uuid.IdGeneratorSnowflake;
import com.ruoyi.system.domain.PracticeCadetMasterSkill;
import com.ruoyi.system.domain.PracticeCadetMasterSkillCount;
import com.ruoyi.system.mapper.PracticeCadetMasterSkillMapper;
import com.ruoyi.system.service.IPracticeCadetMasterSkillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 实践掌握技能Service业务层处理
 *
 * @author dp
 * @date 2023-12-02
 */
@Service
public class PracticeCadetMasterSkillServiceImpl implements IPracticeCadetMasterSkillService {
    @Autowired
    private PracticeCadetMasterSkillMapper practiceCadetMasterSkillMapper;
    @Autowired
    IdGeneratorSnowflake idGeneratorSnowflake;

    /**
     * 查询实践掌握技能
     *
     * @param masterSkillId 实践掌握技能主键
     * @return 实践掌握技能
     */
    @Override
    public PracticeCadetMasterSkill selectPracticeCadetMasterSkillByMasterSkillId(Long masterSkillId) {
        return practiceCadetMasterSkillMapper.selectPracticeCadetMasterSkillByMasterSkillId(masterSkillId);
    }

    /**
     * 查询实践掌握技能列表
     *
     * @param practiceCadetMasterSkill 实践掌握技能
     * @return 实践掌握技能
     */
    @Override
    public List<PracticeCadetMasterSkill> selectPracticeCadetMasterSkillList(PracticeCadetMasterSkill practiceCadetMasterSkill) {
        return practiceCadetMasterSkillMapper.selectPracticeCadetMasterSkillList(practiceCadetMasterSkill);
    }

    /**
     * 查询实践掌握技能合计列表
     *
     * @param submitBegin
     * @param submitEnd
     * @param baseId
     * @param masterSkillStatus
     * @return
     */
    @Override
    public List<PracticeCadetMasterSkillCount> selectPracticeCadetMasterSkillCount(String submitBegin, String submitEnd, String baseId, String masterSkillStatus) {
        return practiceCadetMasterSkillMapper.selectPracticeCadetMasterSkillCount(submitBegin, submitEnd, baseId, masterSkillStatus);
    }

    /**
     * 根据条件查询实践掌握技能列表
     *
     * @param submitBegin
     * @param submitEnd
     * @param baseId
     * @param cadetId
     * @param masterSkillStatus
     * @return
     */
    @Override
    public List<PracticeCadetMasterSkill> getMasterSkillList(String submitBegin, String submitEnd, String baseId, String cadetId, String masterSkillStatus) {
        return practiceCadetMasterSkillMapper.getMasterSkillList(submitBegin, submitEnd, baseId, cadetId, masterSkillStatus);
    }

    /**
     * 新增实践掌握技能
     *
     * @param practiceCadetMasterSkill 实践掌握技能
     * @return 结果
     */
    @Override
    public int insertPracticeCadetMasterSkill(PracticeCadetMasterSkill practiceCadetMasterSkill) {
        return practiceCadetMasterSkillMapper.insertPracticeCadetMasterSkill(practiceCadetMasterSkill);
    }

    /**
     * 修改实践掌握技能
     *
     * @param practiceCadetMasterSkill 实践掌握技能
     * @return 结果
     */
    @Override
    public int updatePracticeCadetMasterSkill(PracticeCadetMasterSkill practiceCadetMasterSkill) {
        return practiceCadetMasterSkillMapper.updatePracticeCadetMasterSkill(practiceCadetMasterSkill);
    }

    /**
     * 批量删除实践掌握技能
     *
     * @param masterSkillIds 需要删除的实践掌握技能主键
     * @return 结果
     */
    @Override
    public int deletePracticeCadetMasterSkillByMasterSkillIds(Long[] masterSkillIds) {
        return practiceCadetMasterSkillMapper.deletePracticeCadetMasterSkillByMasterSkillIds(masterSkillIds);
    }

    /**
     * 删除实践掌握技能信息
     *
     * @param masterSkillId 实践掌握技能主键
     * @return 结果
     */
    @Override
    public int deletePracticeCadetMasterSkillByMasterSkillId(Long masterSkillId) {
        return practiceCadetMasterSkillMapper.deletePracticeCadetMasterSkillByMasterSkillId(masterSkillId);
    }

    /**
     * 实体数据补全
     *
     * @param practiceCadetMasterSkill 实体
     * @param userId                   用户id
     * @param crateType                创建类型 1：新增 2：修改
     */
    @Override
    public void completeData(PracticeCadetMasterSkill practiceCadetMasterSkill, Long userId, Integer crateType) {
        //主键
        if (practiceCadetMasterSkill.getMasterSkillId() == null || "".equals(practiceCadetMasterSkill.getMasterSkillId())) {
            practiceCadetMasterSkill.setMasterSkillId(ExtHelper.toString(idGeneratorSnowflake.nextId()));
        }
        //创建人、创建时间
        if (crateType == 1) {
            if (practiceCadetMasterSkill.getCreateBy() == null) {
                practiceCadetMasterSkill.setCreateBy(userId.toString());
            }
            if (practiceCadetMasterSkill.getCreateTime() == null) {
                practiceCadetMasterSkill.setCreateTime(DateUtils.getNowDate());
            }
        }
        //修改人
        if (practiceCadetMasterSkill.getModifyBy() == null) {
            practiceCadetMasterSkill.setModifyBy(userId);
        }
        //修改时间
        if (practiceCadetMasterSkill.getModifyTime() == null) {
            practiceCadetMasterSkill.setModifyTime(DateUtils.getNowDate());
        }
    }
}
